package com.kfm.company.controller;

import com.kfm.company.model.Emp;
import com.kfm.company.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/emp")
@Slf4j
public class EmpController {

    @Autowired
    EmpService empService;


    @RequestMapping("/list")
    public ModelAndView list() {
        ModelAndView mv = new ModelAndView();
        List<Emp> list = empService.findAll();
        if (list != null) {
            log.info("查询成功");
        } else {
            log.error("查询失败");
        }
        mv.addObject("list", list);
        // thymeleaf 在resources目录下的templates中找 emp/list.html
        mv.setViewName("/emp/list");

        return mv;
    }

    @RequestMapping("/info")
    public String info() {
        // thymeleaf 在resources目录下的templates中找info.html
        return "info";
    }

}
